package com.linkhub.oms.data.sync.api.wms.domain.request;

import com.alibaba.fastjson.annotation.JSONField;
import com.linkhub.oms.common.util.QtBeanUtil;
import com.linkhub.oms.data.sync.api.wms.domain.dto.WmsProcessOrderCreateDTO;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Jaycle
 * @version 1.0.0
 * @Description StoreProcessCreateRequest.java
 * @createTime 2024/06/20 13:41
 */
@NoArgsConstructor
@Data
public class StoreProcessCreateRequest implements Serializable {
    /**
     * request
     */
    @JSONField(name = "request")
    private Request request;

    public static StoreProcessCreateRequest createRequest( WmsProcessOrderCreateDTO wmsProcessOrderCreateDTO ) {
        StoreProcessCreateRequest storeProcessCreateRequest = new StoreProcessCreateRequest();
        storeProcessCreateRequest.request = new Request();
        QtBeanUtil.copyProperties(wmsProcessOrderCreateDTO, storeProcessCreateRequest.request);

        if (wmsProcessOrderCreateDTO.getMaterialitems() != null && wmsProcessOrderCreateDTO.getMaterialitems().getItem() != null) {
            storeProcessCreateRequest.request.setMaterialItems(new Request.MaterialItems());
            List<Request.MaterialItems.Item> materialItemsList = new ArrayList<>();
            for (WmsProcessOrderCreateDTO.MaterialItems.MaterialItem materialItem : wmsProcessOrderCreateDTO.getMaterialitems().getItem()) {
                Request.MaterialItems.Item item = new Request.MaterialItems.Item();
                QtBeanUtil.copyProperties(materialItem, item);
                materialItemsList.add(item);
            }
            storeProcessCreateRequest.request.getMaterialItems().setItem(materialItemsList);
        }

        if (wmsProcessOrderCreateDTO.getProductitems() != null && wmsProcessOrderCreateDTO.getProductitems().getItem() != null) {
            storeProcessCreateRequest.request.setProductItems(new Request.ProductItems());
            Request.ProductItems.Item productItem = new Request.ProductItems.Item();
            QtBeanUtil.copyProperties(wmsProcessOrderCreateDTO.getProductitems().getItem(), productItem);
            storeProcessCreateRequest.request.getProductItems().setItem(productItem);
        }

        System.out.println(storeProcessCreateRequest);
        return storeProcessCreateRequest;
    }

    @NoArgsConstructor
    @Data
    public static class Request {
        /**
         * ownerCode
         */
        @JSONField(name = "ownerCode")
        private String ownerCode;

        /**
         * warehouseCode
         */
        @JSONField(name = "warehouseCode")
        private String warehouseCode;

        /**
         * processOrderCode
         */
        @JSONField(name = "processOrderCode")
        private String processOrderCode;

        /**
         * orderType
         */
        @JSONField(name = "orderType")
        private String orderType;

        /**
         * orderCreateTime
         */
        @JSONField(name = "orderCreateTime")
        private String orderCreateTime;

        /**
         * planTime
         */
        @JSONField(name = "planTime")
        private String planTime;

        /**
         * serviceType
         */
        @JSONField(name = "serviceType")
        private String serviceType;

        /**
         * remark
         */
        @JSONField(name = "remark")
        private String remark;

        /**
         * recUnitCode
         */
        @JSONField(name = "recUnitCode")
        private String recUnitCode;

        /**
         * extendProps
         */
        @JSONField(name = "extendProps")
        private String extendProps;

        /**
         * planQty
         */
        @JSONField(name = "planQty")
        private String planQty;

        /**
         * materialitems
         */
        @JSONField(name = "materialitems")
        private MaterialItems materialItems;

        @NoArgsConstructor
        @Data
        public static class MaterialItems {
            /**
             * item
             */
            @JSONField(name = "item")
            private List<Item> item;

            @NoArgsConstructor
            @Data
            public static class Item {
                /**
                 * itemCode
                 */
                @JSONField(name = "itemCode")
                private String itemCode;

                /**
                 * quantity
                 */
                @JSONField(name = "quantity")
                private String quantity;

                /**
                 * inventoryType
                 */
                @JSONField(name = "inventoryType")
                private String inventoryType;

                /**
                 * userDefined1
                 */
                @JSONField(name = "userDefined1")
                private String userDefined1;

                /**
                 * ratioQty
                 */
                @JSONField(name = "ratioQty")
                private String ratioQty;
            }
        }

        /**
         * productitems
         */
        @JSONField(name = "productitems")
        private ProductItems productItems;

        @NoArgsConstructor
        @Data
        public static class ProductItems {
            /**
             * item
             */
            @JSONField(name = "item")
            private Item item;

            @NoArgsConstructor
            @Data
            public static class Item {
                /**
                 * itemCode
                 */
                @JSONField(name = "itemCode")
                private String itemCode;

                /**
                 * quantity
                 */
                @JSONField(name = "quantity")
                private String quantity;

                /**
                 * inventoryType
                 */
                @JSONField(name = "inventoryType")
                private String inventoryType;

                /**
                 * userDefined1
                 */
                @JSONField(name = "userDefined1")
                private String userDefined1;

                /**
                 * remark
                 */
                @JSONField(name = "remark")
                private String remark;
            }
        }
    }
}
